package com.yh.controller;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yh.bean.Dept;
import com.yh.bean.PersonApply;
import com.yh.service.PersonApplyService;

@Controller
public class PersonApplyController {
	/*  
	 * 该控制器服务于前段人事申请的功能处理
	 * 
	 * */
	//注入业务层
	@Qualifier("personApplyImp")
	@Autowired
	private  PersonApplyService  pai;
	
	
	//获取申请基本信息
	@RequestMapping("/getInsertInfo")
	public String  getBossName(HttpServletRequest req){
		 HttpSession session=req.getSession();
		 int user_id=Integer.parseInt((String) session.getAttribute("uId"));
		 String  boss=pai.getBossName(user_id);
		 System.out.println(boss);
		 String dept=pai.getDeptName(user_id);
		 req.setAttribute("pa_boss", boss);
		 req.setAttribute("pa_dept", dept);

		return "PersonApply/Apply";
	}
	
	
	//新增申请
	@RequestMapping("/insertPersonApply")
	public  String  insertPersonApply(PersonApply pa,HttpServletRequest  req){
		
		 HttpSession session=req.getSession();
		 pa.setPa_emp(Integer.parseInt((String) session.getAttribute("uId")));
		 pai.setPersonApply(pa);
	   return "PersonApply/showApply";
	}
	
	
	
	
	//查询所有申请
	@ResponseBody
	@RequestMapping("/queryAllApply")
	public Map queryAllApply(int curr){
		System.out.println("查询");
		Map   data=pai.QueryAllApply(curr);

		System.out.println("输出");
		return  data;
	}
	
	
	
	//根据条件查询申请
	@ResponseBody
	@RequestMapping("/queryApply")
	public Map  queryApply(PersonApply form,int curr) {
		
		Map map=pai.QueryApply(form,curr);
	
		return map;
		
	}

	
	
	//删除单条申请
	@ResponseBody
	@RequestMapping("/deleteApply")
	public String deleteApply(PersonApply pa) {
		System.out.println("删除");
		return pai.deleteApply(pa);
	}
	
	
	//删除一个数组申请
	@ResponseBody
	@RequestMapping("/deleteAllApply")
	public String deleteAllApply(@RequestParam("array[]") int [] aa) {

		return pai.deleteArrayApply(aa);
	}
	
	

	
	//老板批阅（更改申请状态）
	@ResponseBody
	@RequestMapping("/BossUpdateApply")
	public String BossUpdateApply(String pa_status,String pa_id) {
		System.out.println("boss更改");
		PersonApply  pa=new PersonApply();
		pa.setPa_status(pa_status);
		pa.setPa_id(Integer.parseInt(pa_id));
		System.out.println(pa);
		return pai.BossUpdateApply(pa);
		
	}

	
	//员工更改申请
	@ResponseBody
	@RequestMapping("/personUpdateApply")
	public String personUpdateApply(PersonApply pa) {
		System.out.println("员工更改");
		return  pai.personUpdateApply(pa);
	} 
	
	
	@ResponseBody
	@RequestMapping("/queryAllDept")
	public List<Dept> queryAllDept() {
		List<Dept> ld=pai.queryAllDept();
		return ld;
		
	}
	
	
	
	

}
